﻿<Page
    x:Class="UniversalApp_Sample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UniversalApp_Sample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mb="using:Huyn.MultiBinding"
    xmlns:converters="using:UniversalApp_Sample.Converters"
    xmlns:multiConverters="using:UniversalApp_Sample.MultiConverters"
    xmlns:viewModels="using:UniversalApp_Sample.ViewModels"
    xmlns:system="using:System"
    mc:Ignorable="d">
    <Page.Resources>
        <multiConverters:ConcatMultiConverter x:Key="ConcatMultiConverter"/>
        <multiConverters:AddMultiConverter x:Key="AddMultiConverter"/>
        <multiConverters:BoolToVisibilityMultiConverter x:Key="BoolToVisibilityMultiConverter"/>
        <converters:ToUpperCaseConverter x:Key="ToUpperCaseConverter"/>

        <Style x:Key="InfoTextBlock" TargetType="TextBlock">
            <Setter Property="FontSize" Value="16"/>
            <Setter Property="FontWeight" Value="Light"/>
            <Setter Property="Foreground" Value="Yellow"/>
            <Setter Property="TextWrapping" Value="Wrap"/>
        </Style>
    </Page.Resources>
    <Page.DataContext>
        <viewModels:MainViewModel/>
    </Page.DataContext>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Hub>
            <HubSection Header="concat texts">
                <DataTemplate>
                    <StackPanel Width="300">
                        <TextBox x:Name="ConcatTextBox1" Text="Text1" HorizontalAlignment="Stretch"/>
                        <TextBox x:Name="ConcatTextBox2" Text="Text2" HorizontalAlignment="Stretch" Margin="0,12"/>
                        <TextBox Text="{Binding StringValue,Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                        <TextBlock Text="binding result:" FontSize="16" Margin="0,12,0,0"/>
                        <TextBlock FontSize="20" TextWrapping="Wrap" Foreground="Cyan">
                   <mb:MultiBindingLinker.Attach>
                       <mb:MultiBindings>
                           <mb:MultiBinding TargetProperty="Text" Converter="{StaticResource ConcatMultiConverter}">
                               <mb:Binding Path="StringValue" />
                               <mb:Binding Path="Text" ElementName="ConcatTextBox1"/>
                               <mb:Binding Path="Text" ElementName="ConcatTextBox2" Converter="{StaticResource ToUpperCaseConverter}"/>
                               <mb:Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
                           </mb:MultiBinding>
                       </mb:MultiBindings>
                   </mb:MultiBindingLinker.Attach>
                        </TextBlock>

                        <TextBlock Style="{StaticResource InfoTextBlock}" Text="Bindings:&#10;- Path=StringValue&#10;- Path=Text ElementName=ConcatTextBox1&#10;- Path=Text ElementName=ConcatTextBox2 Converter=ToUpperCaseConverter&#10;- RelativeSource={RelativeSource Self}&#10;"
                                   Margin="0,12,0,0"/>
                    </StackPanel>
                </DataTemplate>
            </HubSection>
            <HubSection Header="addition">
                <DataTemplate>
                    <StackPanel>
                        <Slider Value="{Binding SliderValue,Mode=TwoWay}" Minimum="0" Maximum="100"/>
                        <Slider x:Name="Slider1" Value="20" Minimum="0" Maximum="100"/>
                        <TextBlock Text="binding result:" FontSize="16" Margin="0,12,0,0"/>
                        <TextBlock FontSize="20" TextWrapping="Wrap" Foreground="Cyan">
                   <mb:MultiBindingLinker.Attach>
                       <mb:MultiBindings>
                           <mb:MultiBinding TargetProperty="Text" Converter="{StaticResource AddMultiConverter}">
                               <mb:Binding Path="SliderValue" />
                               <mb:Binding Path="Value" ElementName="Slider1"/>
                           </mb:MultiBinding>
                           <mb:MultiBinding TargetProperty="FontSize" Converter="{StaticResource AddMultiConverter}">
                               <mb:Binding Path="SliderValue" />
                               <mb:Binding Path="Value" ElementName="Slider1"/>
                           </mb:MultiBinding>
                       </mb:MultiBindings>
                   </mb:MultiBindingLinker.Attach>
                        </TextBlock>
                    </StackPanel>
                </DataTemplate>
            </HubSection>
            <HubSection Header="visibility">
                <DataTemplate>
                    <StackPanel>
                        <CheckBox IsChecked="{Binding BoolValue,Mode=TwoWay}" Content="toggle 1"/>
                        <ToggleButton x:Name="ToogleButton1" IsChecked="True" Content="toggle 2" Margin="0,12,0,0"/>
                        <TextBlock Text="binding result:" FontSize="16" Margin="0,12,0,0"/>
                        <TextBlock  FontSize="20" TextWrapping="Wrap" Foreground="Cyan">
                   <mb:MultiBindingLinker.Attach>
                       <mb:MultiBindings>
                           <mb:MultiBinding TargetProperty="Visibility" Converter="{StaticResource BoolToVisibilityMultiConverter}" ConverterParameter="inverse">
                               <mb:Binding Path="BoolValue" />
                               <mb:Binding Path="IsChecked" ElementName="ToogleButton1"/>
                           </mb:MultiBinding>
                            <mb:MultiBinding TargetProperty="Text" Converter="{StaticResource ConcatMultiConverter}" ConverterParameter="inverse">
                               <mb:Binding Path="BoolValue" ConverterParameter="toggle1" />
                               <mb:Binding Path="IsChecked" ElementName="ToogleButton1" ConverterParameter="toggle1"/>
                           </mb:MultiBinding>
                       </mb:MultiBindings>
                   </mb:MultiBindingLinker.Attach>
                        </TextBlock>
                    </StackPanel>
                </DataTemplate>
            </HubSection>
        </Hub>
    </Grid>
</Page>
